package assignmentstrategy

import (
	"codejy/analysis/codeanalysis"
	"codejy/globalfunc"
	"codejy/store"
	"codejy/structdef"
	"strings"
)

type GlobalMethodStrategy struct {
}

func init() {
	RegisterStrategy(&GlobalMethodStrategy{})
}
func (n GlobalMethodStrategy) getId() int {
	return codeanalysis.GlobalMethod
}

func (n GlobalMethodStrategy) Execute(threadStore *structdef.ThreadStore, code string) string {
	//获取第一个点的位置
	index := strings.Index(code, ".")
	interfaces := globalfunc.ExecuteFunc("SubFunctionCallNameAndParam", code[index+1:]).([]interface{})
	funName, funParams := interfaces[0].(string), interfaces[1].([]string)
	globalfunc.ExecuteFunc("FunctionCallExecute", threadStore, funName, funParams)
	//获取函数返回值
	variable1, _ := store.GetGlobalVariable(threadStore, funName)
	return variable1.Value
}
